<template>
  <div>
    <div>
      <el-descriptions
          class="margin-top"
          :column="2"
          :size="size"
          title="医院信息"
          border
          style="width: 100%"
      >
        <template slot="extra">
          <el-button
              type="warning"
              size="small"
              @click="updateFinaceShow">修改
          </el-button>
        </template>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-first-aid-kit"></i>
            医院
          </template>
          {{ hospitalData.name }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-mobile-phone"></i>
            手机号
          </template>
          {{ hospitalData.phone }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-s-data"></i>
            日诊人数
          </template>
          {{ hospitalData.dailyclinic }}
        </el-descriptions-item>

        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-money"></i>
            床位数
          </template>
          {{ hospitalData.bed }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-office-building"></i>
            邮箱
          </template>
          {{ hospitalData.email }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-map-location"></i>
            地址
          </template>
          {{ hospitalData.address }}
        </el-descriptions-item>

        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-warning-outline"></i>
            隶属性质
          </template>
          {{ hospitalData.membership }}
        </el-descriptions-item>

        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-question"></i>
            医院类别
          </template>
          {{ hospitalData.type }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-mobile-phone"></i>
            总人数
          </template>
          {{ hospitalData.total }}
        </el-descriptions-item>
      </el-descriptions>
    </div>

    <el-dialog
        title="修改融资信息"
        :visible.sync="showUpdate"
        width="580px"
        :before-close="closeUpdate"
    >
      <el-form
          v-model="hospitalData"
          ref="ruleForm"
          label-width="100px"
          class="demo-ruleForm"
      >
        <strong style="color: green">修改医院信息：</strong>

        <el-form-item label="医院：" prop="name">
          <el-input v-model="hospitalData.name"></el-input>
        </el-form-item>
        <el-form-item label="手机号：" prop="phone">
          <el-input v-model="hospitalData.phone"></el-input>
        </el-form-item>
        <el-form-item label="日诊人数：" prop="dailyclinic">
          <el-input v-model="hospitalData.dailyclinic"></el-input>
        </el-form-item>

        <el-form-item label="床位数：" prop="bed">
          <el-input v-model="hospitalData.bed"></el-input>
        </el-form-item>
        <el-form-item label="邮箱：" prop="email">
          <el-input v-model="hospitalData.email"></el-input>
        </el-form-item>
        <el-form-item label="地址：" prop="address">
          <el-input v-model="hospitalData.address"></el-input>
        </el-form-item>

        <el-form-item label="隶属性质：" prop="membership">
          <el-select v-model="hospitalData.membership">
            <el-option v-if="hospitalData.membership != '省级'" label="省级" value="省级"></el-option>
            <el-option v-if="hospitalData.membership != '市级'" label="市级" value="市级"></el-option>
            <el-option v-if="hospitalData.membership != '县级'" label="县级" value="县级"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="医院类别：" prop="type">
          <el-select v-model="hospitalData.type">
            <el-option v-if="hospitalData.type != '三甲'" label="三甲" value="三甲"></el-option>
            <el-option v-if="hospitalData.type != '三乙'" label="三乙" value="三乙"></el-option>
            <el-option v-if="hospitalData.type != '二甲'" label="二甲" value="二甲"></el-option>
            <el-option v-if="hospitalData.type != '二乙'" label="二乙" value="二乙"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="总人数：" prop="total">
          <el-input v-model="hospitalData.total"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="closeUpdate">取 消</el-button>
        <el-button type="success" @click="updateFinace">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import {insertById, selectById} from "@/api/hospital";

export default {
  data() {
    return {
      size: "",
      hospitalData: {
        userId: "",
        name: "",
        phone: "",
        dailyclinic: "", //日均出诊人数
        bed: "",  //床位
        email: "",
        address: "",
        membership: "",
        type: "",
        total: ""
      },
      showUpdate: false,
      value: "",
    };
  },
  methods: {
    updateFinaceShow() {
      this.showUpdate = true;
    },
    updateFinace() {
      if (this.hospitalData.name === "" || this.hospitalData.name == null) {
        alert("医院名不能为空");
        return;
      }
      if (this.hospitalData.address == "" || this.hospitalData.address == null) {
        alert("医院地址不能为空");
        return;
      }
      if (this.hospitalData.membership == "" || this.hospitalData.membership == null) {
        alert("医院隶属性质不能为空");
        return;
      }
      if (this.hospitalData.type == "" || this.hospitalData.type == null) {
        alert("医院类别不能为空");
        return;
      }
      insertById({
        userId: this.$store.state.userId,
        name: this.hospitalData.name,
        phone: this.hospitalData.phone,
        dailyclinic: this.hospitalData.dailyclinic, //日均出诊人数
        bed: this.hospitalData.bed,  //床位
        email: this.hospitalData.email,
        address: this.hospitalData.address,
        membership:this.hospitalData.membership,
        type: this.hospitalData.type,
        total: this.hospitalData.total,
      })
          .then((res) => {
            if (res.flag == true) {
              this.$message.success(res.message);
              this.getData();
              this.showUpdate = false;
            } else {
              this.$message.error(res.data);
            }
          })
          .catch((err) => {
            alert("修改失败，已有提交，但还未审核")
            console.log("修改失败");
          });
    },
    closeUpdate() {
      this.showUpdate = false;
    },
    getData(){
      selectById({
        id: this.$store.state.userId
      }).then((res) => {
        this.hospitalData = res.data;
        console.log(res.data);
      });
    }
  },
  created() {
    this.getData();
  },
};
</script>
<style>
.el-descriptions {
  padding-left: 20px;
  padding-right: 20px;
  padding-bottom: 20px;
}
</style>